<%@page import="com.mysql.cj.xdevapi.JsonArray"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.Array"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ page import="java.io.IOException" %>
<%@page
import="java.io.PrintWriter"
import ="java.net.URLEncoder"
import=" java.sql.Connection"
import ="java.sql.DriverManager"
import ="java.sql.PreparedStatement"
import ="java.sql.ResultSet"
import ="javax.servlet.ServletException"
import=" javax.servlet.annotation.WebServlet"
import ="javax.servlet.http.HttpServlet"
import ="javax.servlet.http.HttpServletRequest"
import=" javax.servlet.http.HttpServletResponse"
import=" javax.swing.JOptionPane" %>

<%@ page import="org.json.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>查看灾情</title>

<%

JSONArray pointls=new JSONArray();

try {
	request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");
	Class.forName("com.mysql.cj.jdbc.Driver");
	Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yj?autoReconnect=true&serverTimezone=GMT","root","root");	
	PreparedStatement p=con.prepareStatement("select * from zq where flag=0&&count!=0 ");
	
	ResultSet res=p.executeQuery();

	
	int i=0;
		while(res.next()) {	
			JSONObject point=new JSONObject();	
			point.put("wd", res.getFloat("site_w"));
			point.put("jd", res.getFloat("site_j"));
			point.put("id", res.getInt("zqid"))	;
			point.put("uid", res.getInt("uid"))	;
			point.put("count", res.getInt("count"))	;
			point.put("goods", res.getString("goods"))	;
			point.put("time", res.getDate("time"))	;
			point.put("message", res.getString("zq_message"))	;
		pointls.put(i, point);
		i++;
	}
		request.setAttribute("pointls", pointls);
		
		
		con.close();p.close();	
		
		
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>

<style type="text/css">
html,body{
    width:100%;
    height:100%;
}
#container{
    width:100%;
    height:95%;
}
*{
    margin:0px;
    padding:0px;
}
body, button, input, select, textarea {
    font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
</style>

<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=XYLBZ-IYFC6-UWMS5-MWU4V-TAKO3-4NFH5"></script>


</head>
<body onload="init();">

<input type = 'hidden' id = 'test' name = 'test' value = '<%=pointls.toString() %>'></input>

<div id="container"></div>


</body>


<script>

function init() {	
    var center = new qq.maps.LatLng(39.916527,116.397128);
    var map = new qq.maps.Map(document.getElementById("container"), {
        center: center,
        zoom: 4
    });
    var infoWin = new qq.maps.InfoWindow({
        map: map
    });
    
  
    var latlngs = new Array();
	
    	var x = document.getElementById("test").value;
    	
    	pointls = JSON.parse(x);
    	
    	
    	for(var i=0;i<pointls.length;i++)
    		{
    			latlngs.push(new qq.maps.LatLng(pointls[i].wd,pointls[i].jd));
    		}
         
   
    	 var anchor = new qq.maps.Point(6, 6),
         size = new qq.maps.Size(24, 24),
         origin = new qq.maps.Point(0, 0),
         icon = new qq.maps.MarkerImage('https://mapapi.qq.com/web/lbs/javascriptV2/demo/img/center.gif', size, origin, anchor);
    for(var i = 0;i < latlngs.length; i++) {
    	(function(n){
            var marker = new qq.maps.Marker({
            	icon: icon,
            	position: latlngs[n],
                map: map
            });
            qq.maps.event.addListener(marker, 'click', function() {
                infoWin.open();
                infoWin.setContent('<div style="text-align:center;white-space:'+
                'nowrap;margin:10px;">灾情id: ' +
                pointls[n].id+ '<button ><a href="detail.jsp?id='+pointls[n].id+''+'&goods='+pointls[n].goods+''+'&wd='+pointls[n].wd+''+'&jd='+pointls[n].jd+'">调配</a></button> <br>用户ID: ' +
                pointls[n].uid+'<br><br>物资: ' +
                pointls[n].goods+'<br><br>数量: ' +
                pointls[n].count+'<br><br>时间: ' +
                pointls[n].time+'<br><br>描述: ' +
                pointls[n].message+'<button ><a href="foujue.jsp?id='+pointls[n].id+'">否决</a></button><br></div>');
                infoWin.setPosition(latlngs[n]);
            });
        })(i);
    }
}
</script>


</html>
